/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sourcecodeexecutor;

import executor.SC_Executor;
import executor.SC_ExecutorHelper;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

/**
 *
 * @author ryuju
 */
public class SourceCodeExecuteServer {
      /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            System.out.println("SourceCode Execute Server is staring..");
            
            ORB orb = ORB.init(args, null);
            
            POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
            rootpoa.the_POAManager().activate();
            
            // crate SC_Executor
            SourceCodeExecutor executor = new SourceCodeExecutor();
            
            executor.setORB(orb);
            
            org.omg.CORBA.Object execRef = rootpoa.servant_to_reference(executor);
            
            SC_Executor sc_executor = SC_ExecutorHelper.narrow(execRef);
            
            org.omg.CORBA.Object objRef = 
                    orb.resolve_initial_references("NameService");
            
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
            
            String name = "SC_Executor";
            NameComponent path[] = ncRef.to_name(name);
            ncRef.rebind(path, sc_executor);
            
            System.out.println("SourceCode Executor Server is running...");
            orb.run();
            
        } catch (Exception ex) {
            Logger.getLogger(SourceCodeExecuteServer.class.getName()).log(Level.SEVERE, null, ex);
        } 
        
        System.out.println("SourceCode Executor Server is exited...");
    }
}
